home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / src / pt-fcn.h < prev    next >
C/C++ Source or Header  |  1996-05-13  |  5KB  |  206 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if !defined (octave_tree_fcn_h)
  24. #define octave_tree_fcn_h 1
  25.  
  26. #if defined (__GNUG__)
  27. #pragma interface
  28. #endif
  29.  
  30. #include <ctime>
  31.  
  32. class ostream;
  33.  
  34. #include <string>
  35.  
  36. class tree_parameter_list;
  37. class tree_statement_list;
  38. class tree_va_return_list;
  39.  
  40. class tree_walker;
  41.  
  42. #include "oct-obj.h"
  43. #include "symtab.h"
  44. #include "pt-fvc.h"
  45.  
  46. // User defined functions.
  47.  
  48. class
  49. tree_function : public tree_fvc
  50. {
  51. public:
  52.  
  53.   tree_function (int l = -1, int c = -1) : tree_fvc (l, c)
  54.     { init (); }
  55.  
  56.   tree_function (tree_statement_list *cl, symbol_table *st,
  57.          int l = -1, int c = -1)
  58.      : tree_fvc (l, c)
  59.        {
  60.      init ();
  61.      sym_tab = st;
  62.      cmd_list = cl;
  63.      install_nargin_and_nargout ();
  64.        }
  65.  
  66.   ~tree_function (void);
  67.  
  68. //  tree_function *define (tree_statement_list *t);
  69.   tree_function *define_param_list (tree_parameter_list *t);
  70.   tree_function *define_ret_list (tree_parameter_list *t);
  71.  
  72.   void stash_fcn_file_name (void);
  73.  
  74.   void stash_fcn_file_time (time_t t)
  75.     { t_parsed = t; }
  76.  
  77.   string fcn_file_name (void)
  78.     { return file_name; }
  79.  
  80.   time_t time_parsed (void)
  81.     { return t_parsed; }
  82.  
  83.   void mark_as_system_fcn_file (void);
  84.  
  85.   bool is_system_fcn_file (void) const
  86.     { return system_fcn_file; }
  87.  
  88.   bool takes_varargs (void) const;
  89.  
  90.   void octave_va_start (void)
  91.     { curr_va_arg_number = num_named_args; }
  92.  
  93.   octave_value octave_va_arg (void);
  94.  
  95.   octave_value_list octave_all_va_args (void);
  96.  
  97.   bool takes_var_return (void) const;
  98.  
  99.   void octave_vr_val (const octave_value& val);
  100.  
  101.   void stash_function_name (const string& s);
  102.  
  103.   string function_name (void)
  104.     { return fcn_name; }
  105.  
  106.   octave_value eval (bool print);
  107.  
  108.   octave_value_list eval (bool print, int nargout, const octave_value_list& args);
  109.  
  110.   void traceback_error (void);
  111.  
  112.   tree_parameter_list *parameter_list (void) { return param_list; }
  113.  
  114.   tree_parameter_list *return_list (void) { return ret_list; }
  115.  
  116.   tree_statement_list *body (void) { return cmd_list; }
  117.  
  118.   void accept (tree_walker& tw);
  119.  
  120. private:
  121.  
  122.   // List of arguments for this function.  These are local variables.
  123.   tree_parameter_list *param_list;
  124.  
  125.   // List of parameters we return.  These are also local variables in
  126.   // this function.
  127.   tree_parameter_list *ret_list;
  128.  
  129.   // The list of commands that make up the body of this function.
  130.   tree_statement_list *cmd_list;
  131.  
  132.   // The local symbol table for this function.
  133.   symbol_table *sym_tab;
  134.  
  135.   // Used to keep track of recursion depth.
  136.   int call_depth;
  137.  
  138.   // The name of the file we parsed
  139.   string file_name;
  140.  
  141.   // The name of the function.
  142.   string fcn_name;
  143.  
  144.   // The time the file was parsed.
  145.   time_t t_parsed;
  146.  
  147.   // True if this function came from a file that is considered to be a
  148.   // system function.  This affects whether we check the time stamp
  149.   // on the file to see if it has changed.
  150.   bool system_fcn_file;
  151.  
  152.   // The number of arguments that have names.
  153.   int num_named_args;
  154.  
  155.   // The values that were passed as arguments.
  156.   octave_value_list args_passed;
  157.  
  158.   // The number of arguments passed in.
  159.   int num_args_passed;
  160.  
  161.   // Used to keep track of the current offset into the list of va_args.
  162.   int curr_va_arg_number;
  163.  
  164.   // The list of return values when an unspecified number can be
  165.   // returned.
  166.   tree_va_return_list *vr_list;
  167.  
  168.   // The symbol record for nargin in the local symbol table.
  169.   symbol_record *nargin_sr;
  170.  
  171.   // The symbol record for nargout in the local symbol table.
  172.   symbol_record *nargout_sr;
  173.  
  174.   void print_code_function_header (void);
  175.   void print_code_function_trailer (void);
  176.  
  177.   void install_nargin_and_nargout (void);
  178.  
  179.   void bind_nargin_and_nargout (int nargin, int nargout);
  180.  
  181.   void init (void)
  182.     {
  183.       call_depth = 0;
  184.       param_list = 0;
  185.       ret_list = 0;
  186.       sym_tab = 0;
  187.       cmd_list = 0;
  188.       t_parsed = 0;
  189.       system_fcn_file = 0;
  190.       num_named_args = 0;
  191.       num_args_passed = 0;
  192.       curr_va_arg_number = 0;
  193.       vr_list = 0;
  194.     }
  195. };
  196.  
  197. extern void symbols_of_pt_fcn (void);
  198.  
  199. #endif
  200.  
  201. /*
  202. ;;; Local Variables: ***
  203. ;;; mode: C++ ***
  204. ;;; End: ***
  205. */
  206.